package com.example.gausspaper.repository;
import com.example.gausspaper.domain.Paper;
import com.example.gausspaper.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Optional;
@Repository
public interface PaperRepository extends JpaRepository<Paper,String> {
    String type = null;
    Optional<Paper> findById(String userId);

//    @Transactional
//    @Modifying
//    @Query(value = "insert into db_paper (paper_id, bib_tex, author, dataset_names, github_link, meeting, pdf_link, " +
//            "publish_time, title, type) values (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)", nativeQuery = true)
//    void register(String id, String bibTex, String author, String datasetNames, String githubLink, String meeting,
//                  String pdfLink, String publishTime, String title, String type);

    @Transactional
    @Modifying
    @Query("delete from db_paper where paper_id = ?1")
    void deletePaper(String id);

    @Transactional
    @Modifying
    @Query(value = "insert into db_paper_use_dataset (paper_id, dataset_name, paper_title) values (?1, ?2, ?3)",
            nativeQuery = true)
    void addPaperUseDataset(String id,String datasetNames,String title);

    @Transactional
    @Modifying
    @Query(value = "insert into db_paper_has_tag (paper_id, tag_name) values (?1, ?2)", nativeQuery = true)
    void addPaperHasTag(String id,String tagName);


    /*@Transactional
    @Modifying
    @Query("update db_paper set title = ?2 where paper_id = ?1")
    void changeTitle(String id, String newTitle);

    @Transactional
    @Modifying
    @Query("update db_paper set meeting = ?2 where paper_id = ?1")
    void changeMeeting(String id, String newMeeting);

    @Transactional
    @Modifying
    @Query("update db_paper set dataset_names = ?2 where paper_id = ?1")
    void changeDatasets(String id, String newDatasets);*/

}
